<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Admin_Template extends Controller_Template
{
    public $template = 'admin/template';
    
    public function before()
    {
        parent::before();
        
        if(!Auth::instance()->logged_in('admin')) {
            $uri = '/'.Request::$initial->uri();
            if(strpos($uri, 'admin/login') === false)
                Session::instance()->set('redirect', $uri);
            
            Request::$initial->redirect('admin/login');
        }
        
        if ($this->auto_render)
  	{
  	    $this->template->title   = 'Управляй сайтом с B&H!';
             			
  	    $this->template->styles = array();
            $this->template->scripts = array();
        }
        
    }    

    
    public function after()
    {
        if ($this->auto_render)
	{
	    $styles = array(
		'css/reset.css' => 'screen',
		'css/admin/general.css' => 'screen',
            );
  
	    $scripts = array(
		'js/jquery-1.6.4.min.js',
            );
            
            $menu = array(
                array('name' => 'Меню сайта', 'href' => '/admin/chapter'),
                array('name' => 'Статьи', 'href' => '/admin/article'),
                //array('name' => 'Файлы', 'href' => '/admin/file'),
                array('name' => 'Новости', 'href' => '/admin/news'),
                array('name' => 'Каталог товаров', 'href' => '/admin/catalogue'),            
            );
		
            $this->template->styles = array_merge($styles, $this->template->styles);
            $this->template->scripts = array_merge($scripts, $this->template->scripts);
            $this->template->menu = $menu;
	}
	
	$this->response->headers(array('Cache-Control' => 'no-cache'));
    
        parent::after();   
    }
}